package com.lt.contract.bean.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

public class Utils {

    /**
     * post 对象验证是否符合对象要求
     * @param bindingResult
     * @return
     */
    public static String hasErrors(BindingResult bindingResult){
        StringBuffer stringBuffer = new StringBuffer();
        if (bindingResult.hasErrors()) {
            List<ObjectError> list = bindingResult.getAllErrors();
            for (ObjectError objectError : list) {
                stringBuffer.append(objectError.getDefaultMessage());
                stringBuffer.append("---");
            }
        }
        return stringBuffer.toString();
    }
}
